/*
 * @Description: 路由
 * @Autor: HuiSir<273250950@qq.com>
 * @Date: 2021-09-01 16:37:47
 * @LastEditTime: 2023-03-30 10:22:58
 */
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import Home from "@/views/home.vue";
import beforeEachHook from './beforeEachHook'
import afterEachHook from './afterEachHook'

/**
 * 配置规则：
 * 路由path前加“/”代表根节点
 * name:'router-name'            // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * meta: { title: "首页" }        // 页面title
 */

const routes: RouteRecordRaw[] = [
  {
    path: "/",
    name: "home",
    component: Home,
    meta: { title: "首页" },
  },
  {
    path: "/test1",
    name: "test1",
    component: () => import("@/views/test1.vue"),
    meta: { title: "测试页面1" },
  },
  {
    path: "/test2",
    name: "test2",
    component: () => import("@/views/test2.vue"),
    meta: { title: "测试页面2" },
  },
  {
    // 404
    path: "/:pathMatch(.*)",
    redirect: { name: "home" },
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

// 路由权限验证
router.beforeEach(beforeEachHook)

// 路由切换后钩子
router.afterEach(afterEachHook)

export default router;
